Name: Aniket Tiwari
ID: 8866818
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
import plotly.offline as plotly
import pandas as pd
plotly.offline.init_notebook_mode()
The average monthly temperatures of Tokyo, London, and New York are graphically contrasted over the course of a year in this line chart. The seasonal temperature fluctuations are depicted clearly by the individual lines for each city.
# Sample data
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
new_york_temps = [0, 1, 5, 11, 16, 21, 24, 23, 19, 14, 8, 3]
london_temps = [4, 5, 7, 9, 13, 16, 19, 19, 16, 12, 8, 5]
tokyo_temps = [5, 6, 9, 14, 19, 9, 15, 16, 4, 6, 9, 8]
plt.plot(months, new_york_temps, label='New York')
plt.plot(months, london_temps, label='London')
plt.plot(months, tokyo_temps, label='Tokyo')
plt.title('Average Monthly Temperatures in Different Cities')
plt.xlabel('Month')
plt.ylabel('Temperature (°C)')
plt.legend()
plt.show()
The bar chart shoes the results of a poll on preferred movie genres, which also shows how many votes each genre earned. For aesthetic appeal, the chart is color-coded in orange and has bars for action, comedy, drama, and other genres.
genres = ['Action', 'Comedy', 'Drama', 'Fantasy', 'Horror', 'Romance', 'Sci-fi', 'Thriller']
votes = [120, 150, 80, 90, 50, 60, 140, 110]
plt.figure(figsize=(10, 6))
plt.bar(genres, votes, color='orange')
plt.title('Favorite Movie Genres Survey Results')
plt.xlabel('Movie Genre')
plt.ylabel('Number of Votes')
for i in range(len(genres)):
plt.text(i, votes[i] + 5, str(votes[i]), ha='center')
plt.show()
This visualisation counts the number of customer memberships that fall into the "Basic" and "Premium" categories using a horizontal bar plot. Using the Seaborn package and a 'winter' colour scheme, the plot provides a clear comparison of membership numbers.
customer_data = {
'Age': [22, 45, 30, 35, 21, 55, 37, 40, 40, 31, 26, 27, 60, 18, 25, 38, 49, 36, 52, 41, 28, 33, 19, 20, 29],
'Membership': ['Basic', 'Premium', 'Basic', 'Basic', 'Premium', 'Basic', 'Premium', 'Basic', 'Premium', 'Basic',
'Basic', 'Premium', 'Basic', 'Premium', 'Basic', 'Premium', 'Basic', 'Premium', 'Basic', 'Premium',
'Basic', 'Premium', 'Basic', 'Premium', 'Basic']
}
df = pd.DataFrame(customer_data)
plt.figure(figsize=(8, 6))
sns.countplot(y='Membership', data=df, palette='winter')
plt.title('Count of Customer Memberships')
plt.ylabel('Membership Type')
plt.xlabel('Count')
plt.show()
The scatter plot illustrates the connection between employee performance ratings and hours worked. Colour serves as a distinctive identifier for each employee, emphasizing differences in performance based on working hours.
# Sample data
employee_ids = ['E1', 'E2', 'E3', 'E4', 'E5', 'E6', 'E7', 'E8', 'E9', 'E10']
performance = [7.8, 8.5, 6.2, 7.0, 9.1, 8.3, 5.7, 6.8, 7.5, 8.9] # Performance rating out of 10
hours_worked = [35, 40, 30, 45, 50, 42, 38, 36, 39, 48]
data = pd.DataFrame({'Employee': employee_ids, 'Performance': performance, 'Hours Worked': hours_worked})
plt.figure(figsize=(10, 6))
sns.scatterplot(data=data, x='Hours Worked', y='Performance', hue='Employee', palette='viridis')
plt.title('Employee Performance vs Hours Worked')
plt.show()
The observed count of different species in a conservation area is visually represented by this bar plot, which was made with Plotly Express. Every species, including insects, reptiles, amphibians, birds, and mammals, can be identified by its unique colour.
Learn more about wildlife conservation by clicking on the link
data = {
'Species': ['Bird', 'Mammal', 'Reptile', 'Amphibian', 'Insect'],
'Observed Count': [120, 80, 50, 30, 150] }
df = pd.DataFrame(data)
fig = px.bar(df, x='Species', y='Observed Count', color='Species',
labels={'Observed Count': 'Count of Individuals'},
title='Species Distribution in a Conservation Area')
fig.show()
The CO2 emissions of several nations, including the US, China, India, Russia, and Brazil, based on the table below are shown in this choropleth map. The map provides a visual comparison of the environmental impact of each country by representing different emission levels using a colour continuous scale.
| Country | CO2 Emissions (million metric tons) | Year |
|---|---|---|
| United States | 5000 | 2020 |
| China | 7000 | 2020 |
| India | 3000 | 2020 |
| Russia | 2500 | 2020 |
| Brazil | 1000 | 2020 |
data = {
'Country': ['United States', 'China', 'India', 'Russia', 'Brazil'],
'CO2 Emissions': [5000, 7000, 3000, 2500, 1000], # in million metric tons
'Year': [2020, 2020, 2020, 2020, 2020]
}
df = pd.DataFrame(data)
fig = px.choropleth(df, locations='Country', locationmode='country names',
color='CO2 Emissions', hover_name='Country',
color_continuous_scale=px.colors.sequential.Plasma,
title='Global CO2 Emissions in 2020')
fig.show()
